﻿#region 命名空间

using System;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;
using WinnerCMS.WebControls;
using WinnerCMS.WebFactory;

#endregion

namespace WinnerCMS.WebUI.Admin.Shop
{
    [Access("Invoice")]
    public partial class Invoice : PageBase
    {
        private byte ModelId;
        private readonly InvoiceManage _myBLL = new InvoiceManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ModelId = byte.Parse(Request.QueryString["ModelId"]);
            if (!IsPostBack)
            {
                this.lblPath.Text = string.Format("{0} → 销售 → 发票记录管理", ModelManage.GetModelName(this.ModelId));
                BindList(1);
            }
        }

        private void BindList(int PageNo)
        {
            this.GV_List.EmptyDataTemplate = GetTemplate(this);
            var pp = new PagingParam();
            pp.PageNo = PageNo;
            pp.PageSize = this.PageNavigation1.PageSize;
            this.GV_List.DataSource = this._myBLL.BindList(pp);
            this.GV_List.DataBind();
            this.PageNavigation1.RecordCount = pp.RecordCount;

            if (this.GV_List.Rows.Count <= 0)
            {
                this.btnDelSeletedID.Enabled = false;
            }
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            this._myBLL.Delete(this.GV_List.DataKeys[e.RowIndex].Value.ToString(), this.UpdatePanel1);
            BindList(1);
        }

        protected void PageNavigation1_PageChanging(object src, PageChangingEventArgs e)
        {
            BindList(e.NewPageIndex);
        }

        protected void btnDelSeletedID_Click(object sender, EventArgs e)
        {
            this._myBLL.Delete(GetSelectedRow.GetIDs(this.GV_List), this.UpdatePanel1);
            BindList(1);
        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var myTableCell = e.Row.Cells[this.GV_List.Columns.Count - 1];
                if (myTableCell.Controls.Count > 0)
                {
                    var btnDel = (LinkButton) myTableCell.Controls[0];

                    btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");
                }
            }
        }
    }
}